using System.Net;
using System.Net.Sockets;

namespace WebServer.BusinessLogic.Communication
{
    public class SocketWrapper : ISocketWrapper
    {
        private Socket _socket;

        private byte[] _buffer;

        public SocketWrapper(Socket socket)
        {
            _socket = socket;
        }

        public EndPoint RemoteEndPoint
        {
            get { return _socket.RemoteEndPoint; }
        }

        public int ReceiveBufferSize
        {
            get { return _socket.ReceiveBufferSize; }
        }

        public virtual int Receive(int bufferSize, SocketFlags flags)
        {
            _buffer = new byte[bufferSize];
            return _socket.Receive(_buffer, bufferSize, flags);
        }

        public virtual int Send(byte[] data)
        {
            return _socket.Send(data);
        }

        public byte[] Buffer
        {
            get { return _buffer; }
        }

        public bool Connected
        {
            get { return _socket.Connected; }
        }

        public void Shutdown(SocketShutdown how)
        {
            _socket.Shutdown(how);
        }

        public void Close()
        {
            _socket.Close();
        }
    }
}